//
//  CompleteRegViewController.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/11/20.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "CompleteRegViewController.h"
#import "MyTabBarViewController.h"
//#import "NewBrandViewController.h"

@interface CompleteRegViewController ()<TTTAttributedLabelDelegate>

@end

@implementation CompleteRegViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];

    self.view.backgroundColor = CSWhiteColor;
    
    [self createSubView];
    
}

-(void)createSubView{
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"done"];
    [self.view addSubview:imageView];
    [imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.view).offset(30);
        
        make.left.mas_equalTo(self.view).offset(20);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = BoldBigFont;
    titleLabel.text = @"恭喜您完成注册";
    [self.view addSubview:titleLabel];
    [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(imageView.mas_bottom).offset(30);
        
        make.left.mas_equalTo(imageView);
    }];
    
    TTTAttributedLabel *detailLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
    detailLabel.font = MidFont;
    detailLabel.lineSpacing = 5;
    detailLabel.numberOfLines = 0;
    detailLabel.lineBreakMode = NSLineBreakByCharWrapping;
    detailLabel.textColor = CSColorFromRGB(0x606166);
    detailLabel.text = @"欢迎使用众拳体育管理系统，接下来将引导创建您的品牌及场馆信息。填写内容越完善，越便于您的场馆推广。";
    [self.view addSubview:detailLabel];
    [detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(22);
        
        make.left.mas_equalTo(titleLabel);
        
        make.right.mas_equalTo(self.view).offset(-20);
    }];
    
    /**
     创建品牌按钮
     */
    UIButton *createBtn = [[UIButton alloc] init];
    createBtn.backgroundColor = ButtonBackGroundColor;
    createBtn.layer.cornerRadius = 4;
    createBtn.layer.masksToBounds = YES;
    [createBtn setTitle:@"创建品牌" forState:UIControlStateNormal];
    [createBtn setTitleColor:CSBlackColor forState:UIControlStateNormal];
    createBtn.titleLabel.font = BigFont;
    [self.view addSubview:createBtn];
    [createBtn addTarget:self action:@selector(createLogo) forControlEvents:UIControlEventTouchUpInside];
    [createBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(detailLabel.mas_bottom).offset(100);
        
        make.left.mas_equalTo(titleLabel);
        
        make.right.mas_equalTo(detailLabel);
        
        make.height.mas_equalTo(50);
    }];
    
    /**
     提示
     */
    TTTAttributedLabel *noticeLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
    noticeLabel.font = MidFont;
    noticeLabel.textColor = TextColor1;
    noticeLabel.delegate = self;
    //检测url
    noticeLabel.enabledTextCheckingTypes=NSTextCheckingTypeLink;
    noticeLabel.linkAttributes = @{(id)kCTForegroundColorAttributeName:TextColor1,NSUnderlineStyleAttributeName:@(1)}; //链接高亮状态文本属性
    noticeLabel.activeLinkAttributes = @{(id)kCTForegroundColorAttributeName:TextColor1,NSUnderlineStyleAttributeName:@(1)};
    [self.view addSubview:noticeLabel];
    NSString *text = @"暂时不创建";
    [noticeLabel setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
        
        NSRange boldRange = [[mutableAttributedString string] rangeOfString:@"暂时不创建" options:NSCaseInsensitiveSearch];
        
        //下划线
        [mutableAttributedString addAttribute:(NSString *)kCTUnderlineStyleAttributeName value:[NSNumber numberWithInt:kCTUnderlineStyleSingle]  range:boldRange];
        
        return mutableAttributedString;
        
    }];
    
    //添加url
    NSRange clickRange = [text rangeOfString:@"暂时不创建" options:NSCaseInsensitiveSearch];
    [noticeLabel addLinkToURL:[NSURL URLWithString:@"http://www.zanshibuchuangjian.com"] withRange:clickRange];
    
    [noticeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
    
        make.top.mas_equalTo(createBtn.mas_bottom).offset(15);
        
        make.centerX.mas_equalTo(self.view);
    }];
}


#pragma mark 创建品牌
-(void)createLogo{
    
//    NewBrandViewController *newBrandVC = [[NewBrandViewController alloc] init];
//    
//    [self.navigationController pushViewController:newBrandVC animated:YES];
}

- (void)attributedLabel:(TTTAttributedLabel*)label didSelectLinkWithURL:(NSURL*)url{
    
    NSLog(@"打印设置的URL%@进行跳转处理",url);
    
    NSString *strUrl = [NSString stringWithFormat:@"%@",url];
    
    if([strUrl isEqualToString:@"http://www.zanshibuchuangjian.com"]){
        
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        
        [userDefault setBool:NO forKey:@"isCompleteInfo"];
        
        [userDefault synchronize];
        
        MyTabBarViewController *myTabVC = [[MyTabBarViewController alloc] init];
        
        [UIApplication sharedApplication].keyWindow.rootViewController = myTabVC;
    }
}

@end
